package com.sz.youban.dt.service;

import java.io.File;

import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;

public class TesGroovy
{
	public static void main(String[] args) throws  Exception {
//		ScriptEngineManager engineManger = new ScriptEngineManager();
//		for(ScriptEngineFactory item : engineManger.getEngineFactories())
//		{
//			System.out.println(item.getEngineName());
//		}
//		ScriptEngine engine = engineManger.getEngineByName("groovy");
//		engine.eval("println '=======hello'");
		
//		while(true){
			
			GroovyClassLoader loader = new GroovyClassLoader();
			File file = new File("groovy/PersonRules.groovy");
//			Class groovyClass = loader.parseClass(new File("groovy/PersonRules.groovy"));
			//------------
			System.out.println(file.getPath());
			System.out.println(file.getAbsolutePath());
			System.out.println(file.getCanonicalPath());
			System.out.println(file.getAbsoluteFile());
			//------------
			Class groovyClass = loader.parseClass(file);
			GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
			Person p = new Person();
			p.setAge(25);
			p.setName("Tom");
			p.setSalary(8000);
			p.setSex("F");
			Object obj = groovyObject.invokeMethod("checkP", p);
			System.out.println(obj);
			groovyObject = null;
			groovyClass = null;
			loader =null;
//		}
	}
}
